home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / ms-0_06.lha / bms-0.06 / mspawn.c < prev    next >
C/C++ Source or Header  |  1993-08-06  |  4KB  |  120 lines

  1. /* mspawn.c -- Mandelbrot-specific, X-independent MandelSpawn code */
  2.    
  3. /*  This file is part of MandelSpawn, a parallel Mandelbrot program.
  4.  
  5.     Copyright (C) 1990, 1991 Andreas Gustafsson
  6.  
  7.     MandelSpawn is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License, version 1,
  9.     as published by the Free Software Foundation.
  10.  
  11.     MandelSpawn is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License,
  17.     version 1, along with this program; if not, write to the Free 
  18.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21.  
  22. #include "mspawn.h"
  23. #include "ms_ipc.h" /* for byteorder conversion functions */
  24.  
  25. void ms_init(ms, wf)
  26.      ms_state *ms;
  27.      struct wf_state *wf;
  28. { ms->mi_count = 0L; /* done no iterations yet */
  29.   ms->chunks_out=0;
  30.   ms->configuration=0;
  31.   ms->workforce=wf;
  32. }
  33.  
  34.  
  35. /* Calculate the various parameters that go into ms.xi.job.  This includes */
  36. /* host to network real number format conversion. */
  37.  
  38. void 
  39. ms_calculate_job_parameters(ms, j)
  40.      ms_state *ms; struct static_job_info *j;
  41. { ms->yrange=ms->xrange *
  42.     ((double) ms->height / (double) ms->width);
  43.   j->julia=ms->julia;
  44.   if(j->julia) /* Julia mode */
  45.   { j->z0.re=double_to_net(ms->center_x - ms->xrange / 2.0);
  46.     j->z0.im=double_to_net(ms->center_y - ms->yrange / 2.0);
  47.     j->corner.re=double_to_net(ms->c_x);
  48.     j->corner.im=double_to_net(ms->c_y);
  49.   }
  50.   else /* Mandelbrot */
  51.   { j->corner.re=double_to_net(ms->center_x - ms->xrange / 2.0);
  52.     j->corner.im=double_to_net(ms->center_y - ms->yrange / 2.0);
  53.     j->z0.re=double_to_net(0.0);
  54.     j->z0.im=double_to_net(0.0);
  55.   }
  56.   j->delta.re=double_to_net(ms->xrange/ms->width);
  57.   j->delta.im=double_to_net(ms->yrange/ms->height);
  58. }
  59.  
  60.  
  61. void ms_dispatch_chunk(ms, client, rect)
  62.      ms_state *ms; char *client; ms_rectangle rect;
  63. { ms_job j;
  64.   ms_client_info client_info;
  65.   client_info.configuration=ms->configuration;
  66.   client_info.s=rect; /* structure assignment */
  67.   /* build a job structure in network byte order */
  68.   j.j.flags=htons(ms->show_interior ? MS_OPT_INTERIOR : 0);
  69.   j.j.julia=htons(ms->job.julia);
  70.   j.j.corner.re=htonl(ms->job.corner.re);
  71.   j.j.corner.im=htonl(ms->job.corner.im);
  72.   j.j.z0.re=htonl(ms->job.z0.re);
  73.   j.j.z0.im=htonl(ms->job.z0.im);
  74.   j.j.delta.re=htonl(ms->job.delta.re);
  75.   j.j.delta.im=htonl(ms->job.delta.im);
  76.   j.j.iteration_limit=htonl(ms->job.iteration_limit);
  77.   j.s.x=htons(rect.x);
  78.   j.s.width=htons(rect.width);
  79.   j.s.y=htons(rect.y);
  80.   j.s.height=htons(rect.height);
  81.   /* ..and put it on the work queue */
  82.   wf_dispatch_chunk(ms->workforce, client,
  83.         (char *) &client_info, sizeof(ms_client_info),
  84.         (char *) &j, sizeof(j));
  85.   ms->chunks_out++; /* one more to wait for */
  86. }
  87.  
  88.  
  89. /* take a rectangular area, split it into pieces and send the pices */
  90. /* out to be calculated */
  91.  
  92. void ms_dispatch_rect(ms, client, rx, ry, rwidth, rheight)
  93.      ms_state *ms;
  94.      char *client;
  95.      unsigned rx, ry, rwidth, rheight; 
  96. { ms_rectangle r;
  97.   unsigned int right_edge = rx+rwidth;
  98.   unsigned int bottom_edge = ry+rheight;
  99.   unsigned int x, y;
  100.   
  101.   for(y=ry; y < bottom_edge; y+=ms->chunk_height) 
  102.     for(x=rx; x < right_edge; x+=ms->chunk_width) 
  103.     { r.x = x;
  104.       r.y = y;
  105.       r.width = MIN(ms->chunk_width, right_edge-x);
  106.       r.height = MIN(ms->chunk_height, bottom_edge-y);
  107.       ms_dispatch_chunk(ms, client, r);
  108.     }
  109.   wf_restart(ms->workforce);
  110. }
  111.  
  112.  
  113. void wf_draw(client, client_data, data)
  114.      char *client;
  115.      char *client_data;
  116.      char *data; 
  117. { ms_draw(client, client_data, data);
  118. }
  119.  
  120.